<?php
// this came from jspath.php
// this is so .js files will have access to some of the pligg variables
$include_login = false; // used in config.php
include_once('../config.php');
header("content-type: application/x-javascript");
?>

var my_base_url='<?php echo my_base_url ?>';
var my_pligg_base='<?php echo my_pligg_base ?>';


<?php
header("content-type: application/x-javascript");
$include_login = false; // used in config.php
include_once('../config.php');
include_once('../Smarty.class.php');

$smarty = new Smarty;
$smarty->config_dir= '';
$smarty->compile_dir = "../templates_c";
$smarty->template_dir = "../templates";
$smarty->config_dir = "..";
$smarty->config_load("/languages/lang_" . pligg_language . ".conf");

$PLIGG_Visual_Vote_Cast = $smarty->get_config_vars('PLIGG_Visual_Vote_Cast');
$PLIGG_Visual_Vote_Report = $smarty->get_config_vars('PLIGG_Visual_Vote_Report');
$PLIGG_Visual_Vote_For_It = $smarty->get_config_vars('PLIGG_Visual_Vote_For_It');
$PLIGG_Visual_Comment_ThankYou_Rating = $smarty->get_config_vars('PLIGG_Visual_Comment_ThankYou_Rating');


?>
dochref = document.location.href.substr(document.location.href.search('/')+2, 1000);
if(dochref.search('/') == -1){
	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref;
} else {
	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref.substr(0, dochref.search('/'));
}
$thisurl = $thisurl + '<?php echo my_pligg_base; ?>';

var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
  try {
	xmlhttp = new XMLHttpRequest ();
  }
  catch (e) {
  xmlhttp = false}
}

function myXMLHttpRequest ()
{
  var xmlhttplocal;
  try {
  	xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}
  catch (e) {
	try {
	xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}
	catch (E) {
	  xmlhttplocal = false;
	}
  }

  if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
	try {
	  var xmlhttplocal = new XMLHttpRequest ();
	}
	catch (e) {
	  var xmlhttplocal = false;
	}
  }
  return (xmlhttplocal);
}

var mnmxmlhttp = Array ();
var xvotesString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;


function vote (user, id, htmlid, md5, value)
{
	//window.alert(document.getElementById('xvotehavegroups-'+htmlid).value);
	group = 0;
	if (document.getElementById('xvotehavegroups-'+htmlid).value > 0) {
		if (document.getElementById('xvotegroup-'+htmlid).style.display.match('none')) {
			document.getElementById('xvotegroup-'+htmlid).style.display='';
			return;
		}
		group = document.getElementById('group-'+htmlid).value;
	}
	
  	if (xmlhttp) {
		url = $thisurl + "/vote.php";
		var mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value + "&group=" + group;
		anonymous_vote = <?php echo anonymous_vote; ?>;
        if (anonymous_vote == false && user == '0') {
            window.location="<?php echo $my_base_url.$my_pligg_base; ?>/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");    
    			target1 = document.getElementById ('xvotes-' + htmlid);    
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
							<?php if(Voting_Method == 1){
								echo "changemnmvalues (htmlid, value, true);";
							}?>
    					} else {
							<?php if(Voting_Method == 2){
								echo "var mySplitResult = xvotesString[htmlid].split('~');\n";
								echo "target3 = document.getElementById ('xvote-' + htmlid);\n";
								echo "target3.style.width = mySplitResult[0] + 'px';\n";
								echo "target4 = document.getElementById ('mnma-' + htmlid);\n";
								echo "target4.innerHTML = mySplitResult[1];\n";
								echo "target5 = document.getElementById ('mnmb-' + htmlid);\n";
								echo "target5.innerHTML = mySplitResult[2];\n";
								echo "target7 = document.getElementById ('xvotes-' + htmlid);\n";
								echo "target7.className = 'star-rating-noh';\n";
							}?>
							<?php if(Voting_Method == 1){
								echo 'if (xvotesString[htmlid].substring (1, 6) == "ERROR") { ';
								echo "alert(xvotesString[htmlid]);  } else {";
								echo "changemnmvalues (htmlid, value, false); } ";
							}?>
    					}
    				}
    			}
    		}
    	}
	}
	document.getElementById('xvotegroup-'+htmlid).style.display='none';
}


function unvote (user, id, htmlid, md5, value)
{
  	if (xmlhttp) {
		url = $thisurl + "/vote.php";
		var mycontent = "unvote=true&id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = <?php echo anonymous_vote; ?>;
        if (anonymous_vote == false && user == '0') {
            window.location="<?php echo $my_base_url.$my_pligg_base; ?>/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");    
				target1 = document.getElementById ('xvotes-' + htmlid);
  				target2 = document.getElementById ('xvote-' + htmlid);    
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						 xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
							<?php if(Voting_Method == 1){
								echo "changemnmvalues (htmlid, value, true);";
								echo 'target2.innerHTML = "<span>' . $PLIGG_Visual_Vote_For_It . '</span>";';
							}?>
						} else {
							<?php if(Voting_Method == 1){
								echo 'if (xvotesString[htmlid].substring (1, 6) == "ERROR") { ';
								echo "alert(xvotesString[htmlid]);  } else {";
								echo 'target2.innerHTML = "<span>' . $PLIGG_Visual_Vote_For_It . '</span>";';
								echo "changemnmvalues (htmlid, value, false); ";
								echo "}";
							}?>							
    					}
    				}
    			}
    		}
    	}
	}
}

function dealurl(urltodeal)
{
	if (xmlhttp) {
		document.getElementById('submit_urlcheckitvalue').innerHTML = '正在检测网址，请稍候...';
		htmlid = 1;
		url = $thisurl + "/dealurl.php";
		mycontent = "urltodeal=" + urltodeal;
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true);
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    					//window.alert(responseString[htmlid]);
    				if (responseString[htmlid].match('badurl:')) {
    					document.getElementById('submit_urlcheckitvalue').innerHTML = '请输入可访问的url';
    					document.getElementById('urlcheck').value = '请输入可访问的url';
    					document.getElementById('trackback').value = '';
    					document.getElementById('alreadydigg').value = 'false';
    					document.getElementById('newreco').style.display = '';
    					document.getElementById('url_is_valid').value = 'false';
    				}
    				if (responseString[htmlid].match('duplicateurl:')) {
    					document.getElementById('submit_urlcheckitvalue').innerHTML = responseString[htmlid].substring(14,responseString[htmlid].length);
    					document.getElementById('urlcheck').value = responseString[htmlid].substring(14,responseString[htmlid].length);
    					document.getElementById('trackback').value = '';
    					document.getElementById('alreadydigg').value = 'true';
    					document.getElementById('newreco').style.display = 'none';
    					document.getElementById('url_is_valid').value = 'true';
    				}
    				if (responseString[htmlid].match('emptytrackback:')) {
    					document.getElementById('submit_urlcheckitvalue').innerHTML = '您是首次推荐者:)';
    					document.getElementById('urlcheck').value = '您是首次推荐者:)';
    					document.getElementById('trackback').value = '';
    					document.getElementById('alreadydigg').value = 'false';
    					document.getElementById('newreco').style.display = '';
    					document.getElementById('url_is_valid').value = 'true';
    				}
    				if (responseString[htmlid].match('gettrackback:')) {
    					document.getElementById('submit_urlcheckitvalue').innerHTML = '您是首次推荐者:)';
    					document.getElementById('urlcheck').value = '您是首次推荐者:)';
    					document.getElementById('trackback').value = responseString[htmlid].substring(14,responseString[htmlid].length);
    					document.getElementById('alreadydigg').value = 'false';
    					document.getElementById('newreco').style.display = '';
    					document.getElementById('url_is_valid').value = 'true';
    				}
    			}
    		}
		}
	}
	
	
}

function cvote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = $thisurl + "/cvote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = <?php echo anonymous_vote; ?>;
        if (anonymous_vote == false && user == '0') {
            window.location="<?php echo $my_base_url.$my_pligg_base; ?>/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);        
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					//window.alert(xvotesString[htmlid]);
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
    						changecvotevalues (htmlid, true);							
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "<?php echo $PLIGG_Visual_Comment_ThankYou_Rating;?>";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function changemnmvalues (id, value, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	//alert(id);
	target1 = document.getElementById ('xvotes-' + id);
	target2 = document.getElementById ('xvote-' + id);
	target3 = document.getElementById ('xreport-' + id);
	target4 = document.getElementById ('xnews-' + id);
	if (error) {
		if (value > 0) { target2.innerHTML = "<span><?php echo $PLIGG_Visual_Vote_Cast;?></span> "; }
		else if (value < 0) { target2.innerHTML = "<span><?php echo $PLIGG_Visual_Vote_Report;?></span> "; }
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
		new Effect.Fade(target3);
		if (value > 0) { target2.innerHTML = "<span><?php echo $PLIGG_Visual_Vote_Cast;?></span> "; }
		else if (value < 0 ) { target2.innerHTML = "<span><?php echo $PLIGG_Visual_Vote_Report;?></span> ";
													new Effect.Opacity(target4, {duration:0.8, from:1.0, to:0.3}); }
	}
	return false;
}

function changecvotevalues (id, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	target1 = document.getElementById ('cvote-' + id);
	if (error) {
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[0] + "人推荐";
		target1.style.backgroundColor = mnmPrevColor[id];
	}
	return false;
}


function enablebutton (button, button2, target)
{
	var string = target.value;
	button2.disabled = false;
	if (string.length > 0) {
		button.disabled = false;
	} else {
		button.disabled = true;
	}
}

function checkfield (type, form, field)
{
	url = $thisurl + '/checkfield.php?type='+type+'&name=' + field.value;
	checkitxmlhttp = new myXMLHttpRequest ();
	checkitxmlhttp.open ("GET", url, true);
	checkitxmlhttp.onreadystatechange = function () {
		if (checkitxmlhttp.readyState == 4) {
		responsestring = checkitxmlhttp.responseText;
			document.getElementById (field.name+'checkitvalue').innerHTML = '<span style="color:red">' + responsestring + '</span>';
			//form.submit.disabled = '';
		}
	}
  checkitxmlhttp.send (null);
  return false;
}

function checkfield_nocolor (type, form, field)
{
	url = $thisurl + '/checkfield.php?type='+type+'&name=' + field.value;
	checkitxmlhttp = new myXMLHttpRequest ();
	checkitxmlhttp.open ("GET", url, true);
	checkitxmlhttp.onreadystatechange = function () {
		if (checkitxmlhttp.readyState == 4) {
		responsestring = checkitxmlhttp.responseText;
			document.getElementById (field.name+'checkitvalue').innerHTML = responsestring;
			//form.submit.disabled = '';
		}
	}
  checkitxmlhttp.send (null);
  return false;
}


function checkvalue (type, form, field)
{
	url = $thisurl + '/checkfield.php?type='+type+'&name=' + field.value;
	checkitxmlhttp = new myXMLHttpRequest ();
	checkitxmlhttp.open ("GET", url, true);
	checkitxmlhttp.onreadystatechange = function () {
		if (checkitxmlhttp.readyState == 4) {
		responsestring = checkitxmlhttp.responseText;
			if (responsestring == "OK") {
				document.getElementById (field.name+'checkitvalue').innerHTML = '<span style="color: #9A9A9A">' + responsestring + '</span>';
			} else {
				document.getElementById (field.name+'checkitvalue').innerHTML = '<span style="color:red">' + responsestring + '</span>';
			}
		}
	}
  checkitxmlhttp.send (null);
  return false;
}


function emailto (original_id, htmlid, instpath, address_count)
{
	email_message = document.getElementById('email_message' + htmlid).value;
	email_address = document.getElementById('email_address_1_' + htmlid).value;
	if (address_count > 1){ 
		for ($i = 2; $i <= address_count; $i++) {
			if(document.getElementById('email_address_' + $i + '_' + htmlid).value != "") {
				email_address = email_address + ', ' + document.getElementById('email_address_' + $i + '_' + htmlid).value;
			}
		}
	}
	
	if (xmlhttp) {
		url = $thisurl + "/recommend.php";
		//mycontent = "email_address=" + escape(email_address) + "&email_to_submit=submit&email_message=" + escape(email_message) + "&original_id=" + original_id + "&backup=0";//cancel escape function because when there is chinese chacracter, wrong happens
		mycontent = "email_address=" + escape(email_address) + "&email_to_submit=submit&email_message=" + email_message + "&original_id=" + original_id + "&backup=0";
		
		target2 = document.getElementById ('emailto-' + htmlid);
		target2.innerHTML = "<br>正在发送，请稍候....";
		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
			
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];						
					} else {
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
		}
	}
}

function show_voter_comments(htmlid)
{
	var votercommentsdisplay=document.getElementById('votercomments-' + htmlid).style.display ? '' : 'none';
	document.getElementById('votercomments-' + htmlid).style.display = votercommentsdisplay;
	/*if (votercommentsdisplay.match('none')) {
		document.getElementById('votercommentsdisplay-' + htmlid).innerHTML = '查看评论';
	}
	else {
		document.getElementById('votercommentsdisplay-' + htmlid).innerHTML = '隐藏评论';
	}*/
	
}

function show_recommend(htmlid, linkid, instpath)
{
	var emailtodisplay=document.getElementById('emailto-' + htmlid).style.display ? '' : 'none';
	document.getElementById('emailto-' + htmlid).style.display = emailtodisplay;

	if (xmlhttp) {
		url = $thisurl + "/recommend.php";
		mycontent = "draw=small&htmlid=" + htmlid + "&linkid=" + linkid;
		target2 = document.getElementById ('emailto-' + htmlid);
		target2.innerHTML = "<br>正在打开，请稍候....";		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;			
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];						
					} else {
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
		}
	}
}

function show_edithunt(htmlid)
{
	var edithuntdisplay=document.getElementById('edithunt-' + htmlid).style.display ? '' : 'none';
	document.getElementById('edithunt-' + htmlid).style.display = edithuntdisplay;
}

function edithunt(htmlid, linkid)
{
	if (xmlhttp) {
		document.getElementById('edithunthint-' + htmlid).innerHTML = '正在修改，请稍候...';
		url = $thisurl + "/edithunt.php";
		//window.alert(document.getElementById('orderdate').value);//cannot get the right value so cancel this function
		mycontent = "xmlhttp=true&linkid=" + linkid + "&newtitle=" + document.getElementById('newtitle-' + htmlid).value + "&newtags=" + document.getElementById('newtags-' + htmlid).value + "&newdesc=" + document.getElementById('desc-' + htmlid).value + "&newdeadline=" + document.getElementById('orderdate').value;
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true);
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText; 
    				//window.alert(responseString[htmlid]); 
    				if (responseString[htmlid].match('success:')) {
    					document.getElementById('edithunthint-' + htmlid).innerHTML = '已成功修改:) 正在刷新，请稍候...';
    					var urlstr = window.location.toString();
    					if (urlstr.match("title=") && urlstr.match("story.php") ) {
    						var index1 = urlstr.indexOf("title=");
    						var index2 = urlstr.indexOf("doing=view_hunt");
    						if (index2 == -1) {
    							var newurlstr = urlstr.substring(0, index1);
    							newurlstr = newurlstr + "id=" + linkid;
    						}
    						else {
	    						var toreplacestr = urlstr.substring(index1,index2);
	    						var newurlstr = urlstr.replace(toreplacestr,"id=" + linkid + "&");
    						}
    						//window.alert(newurlstr);
	    					window.location.href = newurlstr;
    					}
    					else {
    						window.location.reload();
    					}
    					//document.getElementById('edithunt-{$link_shakebox_index}').style.display = 'none';
    				}
    				else {
    					document.getElementById('edithunthint-' + htmlid).innerHTML = '<span style="color:red">未能成功修改,请稍候再试或与站务青铜（forestyaser@163.com）联系</span>';
    				}
    			}
    		}
		}
	}
}

function show_editlink(htmlid)
{
	var editlinkdisplay=document.getElementById('editlink-' + htmlid).style.display ? '' : 'none';
	document.getElementById('editlink-' + htmlid).style.display = editlinkdisplay;
}

function editlinktitileandtags(htmlid, linkid)
{
	if (xmlhttp) {
		document.getElementById('editlinkhint-' + htmlid).innerHTML = '正在修改，请稍候...';
		url = $thisurl + "/editlink.php";
		mycontent = "xmlhttp=true&linkid=" + linkid + "&newtitle=" + document.getElementById('newtitle-' + htmlid).value + "&newtags=" + document.getElementById('newtags-' + htmlid).value;
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true);
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    					//window.alert(responseString[htmlid]); 
    				if (responseString[htmlid].match('success:')) {
    					document.getElementById('editlinkhint-' + htmlid).innerHTML = '已成功修改:) 正在刷新，请稍候...';
    					var urlstr = window.location.toString();
    					if (urlstr.match("title=") && urlstr.match("story.php") ) {
    						var index1 = urlstr.indexOf("title=");
    						var index2 = urlstr.indexOf("doing=view_recoby");
    						if (index2 == -1) {
    							var newurlstr = urlstr.substring(0, index1);
    							newurlstr = newurlstr + "id=" + linkid;
    						}
    						else {
	    						var toreplacestr = urlstr.substring(index1,index2);
	    						var newurlstr = urlstr.replace(toreplacestr,"id=" + linkid + "&");
    						}
    						//window.alert(newurlstr);
	    					window.location.href = newurlstr;
    					}
    					else {
    						window.location.reload();
    					}
    					//document.getElementById('editlink-{$link_shakebox_index}').style.display = 'none';
    				}
    				else {
    					document.getElementById('editlinkhint-' + htmlid).innerHTML = '<span style="color:red">未能成功修改,请稍候再试或与站务青铜（forestyaser@163.com）联系</span>';
    				}
    			}
    		}
		}
	}
}

function editlink(htmlid, linkid)
{
	if (xmlhttp) {
		document.getElementById('editlinkhint-' + htmlid).innerHTML = '正在修改，请稍候...';
		url = $thisurl + "/editlink.php";
		//window.alert(document.getElementById('desc-' + htmlid).value);
		mycontent = "xmlhttp=true&linkid=" + linkid + "&newtitle=" + document.getElementById('newtitle-' + htmlid).value + "&newtags=" + document.getElementById('newtags-' + htmlid).value + "&newdesc=" + document.getElementById('desc-' + htmlid).value;
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true);
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    					//window.alert(responseString[htmlid]); 
    				if (responseString[htmlid].match('success:')) {
    					document.getElementById('editlinkhint-' + htmlid).innerHTML = '已成功修改:) 正在刷新，请稍候...';
    					var urlstr = window.location.toString();
    					if (urlstr.match("title=") && urlstr.match("story.php") ) {
    						var index1 = urlstr.indexOf("title=");
    						var index2 = urlstr.indexOf("doing=view_recoby");
    						if (index2 == -1) {
    							var newurlstr = urlstr.substring(0, index1);
    							newurlstr = newurlstr + "id=" + linkid;
    						}
    						else {
	    						var toreplacestr = urlstr.substring(index1,index2);
	    						var newurlstr = urlstr.replace(toreplacestr,"id=" + linkid + "&");
    						}
    						//window.alert(newurlstr);
	    					window.location.href = newurlstr;
    					}
    					else {
    						window.location.reload();
    					}
    					//document.getElementById('editlink-{$link_shakebox_index}').style.display = 'none';
    				}
    				else {
    					document.getElementById('editlinkhint-' + htmlid).innerHTML = '<span style="color:red">未能成功修改,请稍候再试或与站务青铜（forestyaser@163.com）联系</span>';
    				}
    			}
    		}
		}
	}
}

function replymsg(htmlid,title,sender,receiver,senderlevel)
{
	if (xmlhttp) {
		document.getElementById('reply_msg_hint-' + htmlid).innerHTML = '正在发送，请稍候...';
		url = $thisurl + "/replymsg.php";
		mycontent = "xmlhttp=true" + "&title=" + '回复: '  + title + "&body=" + document.getElementById('reply_msg_content-' + htmlid).value + "&sender=" + sender + "&receiver=" + receiver + "&senderlevel=" + senderlevel;
		//window.alert(mycontent);
		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true);
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    					//window.alert(responseString[htmlid]); 
    				if (responseString[htmlid].match('success')) {
    					document.getElementById('reply_msg_hint-' + htmlid).innerHTML = '<span style="color:#ccc">已成功发送回复:)</span>';
    					var replydisplay=document.getElementById('reply-' + htmlid).style.display ? '' : 'none'; 
    					document.getElementById('reply-' + htmlid).style.display = replydisplay;
    				}
    				if (responseString[htmlid].match('nobody')) {
    					document.getElementById('reply_msg_hint-' + htmlid).innerHTML = '<span style="color:red">请输入回复内容</span>';
    				}
    				if (responseString[htmlid].match('database_error')) {
    					document.getElementById('reply_msg_hint-' + htmlid).innerHTML = '<span style="color:red">发送失败，写数据库时出错</span>';
    				}
    				if (responseString[htmlid].match('fail')) {
    					document.getElementById('reply_msg_hint-' + htmlid).innerHTML = '<span style="color:red">发送失败，请与站务青铜联系，forestyaser@163.com</span>';
    				}
    			}
    		}
		}
	}
}

function delmsg(htmlid,box)
{
	if (xmlhttp) {
		document.getElementById('reply_msg_hint-' + htmlid).innerHTML = '正在删除，请稍候...';
		url = $thisurl + "/delmsg.php";
		mycontent = "xmlhttp=true" + "&msgid=" + htmlid + "&box=" + box;
		//window.alert(mycontent);
		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true);
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    					//window.alert(responseString[htmlid]); 
    				if (responseString[htmlid].match('success')) {
    					document.getElementById('reply_msg_hint-' + htmlid).innerHTML = '<span style="color:#ccc">已成功删除:)</span>';
    					var replydisplay=document.getElementById('msg_wrap-' + htmlid).style.display ? '' : 'none'; 
    					document.getElementById('msg_wrap-' + htmlid).style.display = replydisplay;
    				}
    				if (responseString[htmlid].match('database_error')) {
    					document.getElementById('reply_msg_hint-' + htmlid).innerHTML = '<span style="color:red">删除失败，写数据库时出错</span>';
    				}
    				if (responseString[htmlid].match('fail')) {
    					document.getElementById('reply_msg_hint-' + htmlid).innerHTML = '<span style="color:red">删除失败，请与站务青铜联系，forestyaser@163.com</span>';
    				}
    			}
    		}
		}
	}
}

function sendnewmsg(title,receiver,sender,senderlevel)
{
	if (xmlhttp) {
		document.getElementById('send_msg_hint').innerHTML = '正在发送，请稍候...';
		url = $thisurl + "/sendnewmsg.php";
		mycontent = "xmlhttp=true" + "&title=" + title + "&body=" + document.getElementById('send_msg_content').value + "&sender=" + sender + "&receiver=" + receiver + "&senderlevel=" + senderlevel;
		//window.alert(mycontent);
		
		mnmxmlhttp = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp.open ("POST", url, true);
    		mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp.send (mycontent);
    		mnmxmlhttp.onreadystatechange = function () {
    			if (mnmxmlhttp.readyState == 4) {
    				responseString = mnmxmlhttp.responseText;    					//window.alert(responseString); 
    				if (responseString.match('success')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:green">已成功发送邮件:)</span>';
    				}
    				if (responseString.match('nobody')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:red">请输入正文内容</span>';
    				}
    				if (responseString.match('notitle')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:red">请输入标题内容</span>';
    				}
    				if (responseString.match('database_error')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:red">发送失败，写数据库时出错</span>';
    				}
    				if (responseString.match('fail')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:red">发送失败，请与站务青铜联系，forestyaser@163.com</span>';
    				}
    			}
    		}
		}
	}
}

function declare_owner(htmlid, linkid, ownerid, submitterid, submitternames, ownernames, thingtitle)
{
	//window.alert("htmlid: " + htmlid + " linkid: " + linkid + " ownerid: " + ownerid + " submitterid: " + submitterid );
	if (ownerid == 0) {
		var loc = document.location;
		document.getElementById('declare_owner_hint-' + htmlid).innerHTML = '<span style="color:red">' + '请先<a href="login.php?return='  +loc + '">登录</a></span>';
		return;
	}
	if (xmlhttp) {
		document.getElementById('declare_owner_hint-' + htmlid).innerHTML = '正在发送认领请求，请稍候...';
		url = $thisurl + "/send_owner_declare.php";
		mycontent = "xmlhttp=true&linkid=" + linkid + "&ownerid=" + ownerid + "&submitterid=" + submitterid + "&ownernames=" + ownernames + "&thingtitle=" + thingtitle;
		//window.alert(mycontent);
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true);
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    					//window.alert(responseString[htmlid]); 
    				if (responseString[htmlid].match('success')) {
    					document.getElementById('declare_owner_hint-' + htmlid).innerHTML = '已发送请求到<a href="user.php?uid=' + submitterid + '">' + submitternames + '</a>，请等候处理结果';
    				}
    				else {
    					document.getElementById('declare_owner_hint-' + htmlid).innerHTML = '<span style="color:red">' + '未能成功发送认领请求,请稍候再试或与站务青铜（forestyaser@163.com）联系</span>';
    				}
    			}
    		}
		}
	}
}

function accept_owner_request(linkid, ownerid) {
	//window.alert(ownerid);
	if (xmlhttp) {
		url = $thisurl + "/accept_owner_declare.php";
		mycontent = "xmlhttp=true&linkid=" + linkid + "&ownerid=" + ownerid;
		//window.alert(mycontent);
		htmlid = 1; //indeed this var is no use, I am lazy to change the code
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true);
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    					//window.alert(responseString[htmlid]); 
    				if (responseString[htmlid].match('success')) {
    					window.alert("已成功设置所有者:)");
    				}
    				else {
    					window.alert("未能成功设置所有者，请稍候再试或与站务青铜联系(forestyaser@16.com)");
    				}
    			}
    		}
    	}	
	}
}

function deny_owner_request(linkid, ownerid) {
	//window.alert(ownerid);
	if (xmlhttp) {
		url = $thisurl + "/deny_owner_declare.php";
		mycontent = "xmlhttp=true&linkid=" + linkid + "&ownerid=" + ownerid;
		//window.alert(mycontent);
		htmlid = 1; //indeed this var is no use, I am lazy to change the code
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true);
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    					//window.alert(responseString[htmlid]); 
    				if (responseString[htmlid].match('success')) {
    					window.alert("已拒绝认领请求");
    				}
    				else {
    					window.alert("未能拒绝认领请求，请稍候再试或与站务青铜联系(forestyaser@16.com)");
    				}
    			}
    		}
    	}	
	}
}

function sendprofreq(title,receiver,sender,senderlevel,profile,profilename)
{
	if (xmlhttp) {
		document.getElementById('send_msg_hint').innerHTML = '正在发送，请稍候...';
		url = $thisurl + "/sendprofreq.php";
		mycontent = "xmlhttp=true" + "&title=" + title + "&body=" + document.getElementById('send_msg_content').value + "&sender=" + sender + "&receiver=" + receiver + "&senderlevel=" + senderlevel + "&profile=" + profile + "&email=" + document.getElementById('email').value + "&profilename=" + profilename;
		//window.alert(mycontent);
		
		mnmxmlhttp = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp.open ("POST", url, true);
    		mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp.send (mycontent);
    		mnmxmlhttp.onreadystatechange = function () {
    			if (mnmxmlhttp.readyState == 4) {
    				responseString = mnmxmlhttp.responseText;    					//window.alert(responseString); 
    				if (responseString.match('success')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:green">已成功发送邮件:)</span>';
    				}
    				if (responseString.match('nobody')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:red">请输入认领信息</span>';
    				}
    				if (responseString.match('noemail')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:red">请输入正确的电子邮件</span>';
    				}
    				if (responseString.match('database_error')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:red">发送失败，写数据库时出错</span>';
    				}
    				if (responseString.match('fail')) {
    					document.getElementById('send_msg_hint').innerHTML = '<span style="color:red">发送失败，请与站务青铜联系，forestyaser@163.com</span>';
    				}
    			}
    		}
		}
	}
}

function accept_prof_req(profile,uniqid) {
	email = document.getElementById(uniqid).value;
	url = $thisurl + "/accept_prof_req.php";
	mycontent = "xmlhttp=true&profile=" + profile + "&email=" + email;
	//window.alert(mycontent);
	htmlid = 1; //indeed this var is no use, I am lazy to change the code
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
    	mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    				//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
    				window.alert("已接受认领请求");
    			}
    			else {
    				window.alert("未能成功接受认领请求，请稍候再试或与站务青铜联系(forestyaser@16.com)");
    			}
    		}
    	}
    }
}

function deny_prof_req(profile,uniqid) {
	email = document.getElementById(uniqid).value;
	url = $thisurl + "/deny_prof_req.php";
	mycontent = "xmlhttp=true&profile=" + profile + "&email=" + email;
	//window.alert(mycontent);
	htmlid = 1; //indeed this var is no use, I am lazy to change the code
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
    	mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;    				//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
    				window.alert("已成功拒绝认领请求");
    			}
    			else {
    				window.alert("未能成功拒绝认领请求，请稍候再试或与站务青铜联系(forestyaser@16.com)");
    			}
    		}
    	}
    }
}

function add_apply(htmlid,linkid,userid,submitterid) {
	url = $thisurl + "/add_apply.php";
	mycontent = "xmlhttp=true&linkid=" + linkid + "&userid=" + userid + "&submitterid=" + submitterid;
	//window.alert(mycontent);
	if (!(userid>0)) {
		window.alert('请先登录');
		return;
	}
	if (userid==submitterid) {
		window.alert('您不能认领自己发布的寻人');
		return;
	}
	
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
    	mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
    				window.alert("已成功认领");
    			}
    			else {
    				window.alert("未能成功认领，请稍候再试或与站务青铜联系(forestyaser@16.com)");
    			}
    		}
    	}
    }
}

function switchdiv(htmlid) {
	var divdisplay=document.getElementById('div-' + htmlid).style.display ? '' : 'none';
	document.getElementById('div-' + htmlid).style.display = divdisplay;
}

function update_group() {
	document.getElementById('update_group_hint').innerHTML ='<span>正在保存，请稍候...</span>';

	id = document.getElementById('grp_id').value;
	name = document.getElementById('grp_name').value;
	tags = document.getElementById('grp_tags').value;
	privacy = document.getElementById('grp_privacy').value;
	desc = document.getElementById('grp_desc').value;
	
	url = $thisurl + "/group_update.php";
	mycontent = "xmlhttp=true&grp_id=" + id + "&grp_name=" + name + "&grp_tags=" + tags + "&grp_privacy=" + privacy + "&grp_desc=" + desc;
	
	htmlid = 1;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	
	if (mnmxmlhttp) {
		
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
    				document.getElementById('update_group_hint').innerHTML ='<span style="color:green">成功保存修改</span>';
    				return;
    			}
    			if (responseString[htmlid].match('noname')) {
    				document.getElementById('update_group_hint').innerHTML ='<span style="color:red">请输入小组名字</span>';
    				return;
    			}
    			if (responseString[htmlid].match('nodesc')) {
    				document.getElementById('update_group_hint').innerHTML ='<span style="color:red">请输入小组描述</span>';
    				return;
    			}
    			document.getElementById('update_group_hint').innerHTML ='<span style="color:red">未能成功保存修改，请稍候再试或与站务青铜联系</span>';
    			return;
    		}
    	}
    }
}

function grpsendinvite(receiver,sender,senderlevel,group) {
	//window.alert(receiver+','+sender+','+senderlevel+','+group);
	document.getElementById('hint-'+receiver).innerHTML ='<span>正在发送，请稍候...</span>';
	url = $thisurl + "/group_sendinvite.php";
	mycontent = "xmlhttp=true&receiver=" + receiver + "&sender=" + sender + "&senderlevel=" + senderlevel + "&group=" + group;
	
	htmlid = 1;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
    				document.getElementById('hint-'+receiver).innerHTML ='<span style="color:green">成功发送邀请</span>';
    				return;
    			}
    			if (responseString[htmlid].match('database_error')) {
    				document.getElementById('hint-'+receiver).innerHTML ='<span style="color:red">数据库写入失败，未能成功发送邀请，请稍候再试或与站务青铜联系</span>';
    				return;
    			}
    			document.getElementById('hint-'+receiver).innerHTML ='<span style="color:red">未能成功发送邀请，请稍候再试或与站务青铜联系</span>';
    			return;
    		}
    	}
	}
}

function group_accept_invite(user,group) {
	//window.alert(user+","+group);
	url = $thisurl + "/group_dealuserstate.php";
	mycontent = "xmlhttp=true&user=" + user + "&group=" + group + "&state=approved";
	
	htmlid = 1;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
    				window.alert('已成功接受邀请');
    				return;
    			}
    			window.alert('未能成功接受邀请，请稍候再试或与站务青铜联系');
    			return;
    		}
    	}
	}
}

function group_deny_invite(user,group) {
	//window.alert(user+","+group);
	url = $thisurl + "/group_dealuserstate.php";
	mycontent = "xmlhttp=true&user=" + user + "&group=" + group + "&state=invite_denied";
	
	htmlid = 1;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
    				window.alert('已成功拒绝邀请');
    				return;
    			}
    			window.alert('未能成功拒绝邀请，请稍候再试或与站务青铜联系');
    			return;
    		}
    	}
	}
}

function grpdealuserstate (user,group,state) {
	//window.alert(user+','+group);
	if (state.match('quitted')) {
		okhint = '成功退出小组';
	}
	if (state.match('removed')) {
		okhint = '成功移出小组';
	}
	if (state.match('approved')) {
		okhint = '成功加入小组';
	}
	if (state.match('apply_denied')) {
		okhint = '成功拒绝加入申请';
	}
	
	document.getElementById('hint-'+user).innerHTML ='<span>正在处理，请稍候...</span>';
	url = $thisurl + "/group_dealuserstate.php";
	mycontent = "xmlhttp=true&user=" + user + "&group=" + group + "&state=" + state;
	//window.alert(mycontent);
	htmlid = 1;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:green">' + okhint + '</span>';
	    			return;
    			}
    			document.getElementById('hint-'+user).innerHTML ='<span style="color:red">操作失败，请稍候再试或与站务青铜联系</span>';
    			return;
    		}
    	}
	}
}

function grpdealusertype (user,group,type) {
	//window.alert(user+','+group+','+type);
	if (type.match('admin')) {
		okhint = '成功设为管理员';
	}
	if (type.match('normal')) {
		okhint = '成功设为普通用户';
	}
	document.getElementById('hint-'+user).innerHTML ='<span>正在处理，请稍候...</span>';
	url = $thisurl + "/group_dealusertype.php";
	mycontent = "xmlhttp=true&user=" + user + "&group=" + group + "&type=" + type;
	
	htmlid = 1;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:green">' + okhint + '</span>';
	    			return;
    			}
    			document.getElementById('hint-'+user).innerHTML ='<span style="color:red">操作失败，请稍候再试或与站务青铜联系</span>';
    			return;
    		}
    	}
	}
}

function grpuserindexshow(user,group,show) {
	//window.alert(user+','+group+','+show);
	url = $thisurl + "/group_userindexshow.php";
	mycontent = "xmlhttp=true&user=" + user + "&group=" + group + "&show=" + show;
	//window.alert(mycontent);
	if (show > 0) {
		okhint = '成功设为明星推手';
	}
	else {
		okhint = '成功取消';
		user = 0;
	}
	document.getElementById('hint-'+user).innerHTML ='<span>正在处理，请稍候...</span>';
	htmlid = 1;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:green">' + okhint + '</span>';
	    			renewpusherlist(group);
	    			return;
    			}
    			if (responseString[htmlid].match('already')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:green">已经是明星推手</span>';
	    			return;
    			}
    			if (responseString[htmlid].match('full')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:red">最多能设置8名明星推手</span>';
	    			return;
    			}
    			document.getElementById('hint-'+user).innerHTML ='<span style="color:red">操作失败，请稍候再试或与站务青铜联系</span>';
    			return;
    		}
    	}
	}
}

function renewpusherlist(group) {
	//window.alert(group);
	url = $thisurl + "/group_renewpusher.php";
	mycontent = "xmlhttp=true&group=" + group;
	//window.alert(mycontent);
	document.getElementById('hint-0').innerHTML ='<span style="color:green">操作成功，正在刷新，请稍候...</span>';
	htmlid = 2;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;
    			//window.alert(responseString[htmlid]);
    			document.getElementById('pusher').innerHTML = responseString[htmlid];
    			document.getElementById('hint-0').innerHTML ='';
    		}
    	}
	}
}

function grprecopindexshow(user,link,group,show) {
	//window.alert(link+','+group+','+show);
	url = $thisurl + "/group_recopindexshow.php";
	mycontent = "xmlhttp=true&user=" + user + "&link=" + link + "&group=" + group + "&show=" + show;
	//window.alert(mycontent);
	if (show > 0) {
		okhint = '成功设为精华人物';
	}
	else {
		okhint = '成功取消';
		user = 0;
	}
	document.getElementById('hint-'+user).innerHTML ='<span>正在处理，请稍候...</span>';
	htmlid = 1;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:green">' + okhint + '</span>';
	    			renewrecoplist(group);
	    			return;
    			}
    			if (responseString[htmlid].match('already')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:green">已经是精华人物</span>';
	    			return;
    			}
    			if (responseString[htmlid].match('full')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:red">最多能设置8个人</span>';
	    			return;
    			}
    			document.getElementById('hint-'+user).innerHTML ='<span style="color:red">操作失败，请稍候再试或与站务青铜联系</span>';
    			return;
    		}
    	}
	}
}

function renewrecoplist(group) {
	//window.alert(group);
	url = $thisurl + "/group_renewrecop.php";
	mycontent = "xmlhttp=true&group=" + group;
	//window.alert(mycontent);
	document.getElementById('hint-0').innerHTML ='<span style="color:green">操作成功，正在刷新，请稍候...</span>';
	htmlid = 2;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;
    			//window.alert(responseString[htmlid]);
    			document.getElementById('pusher').innerHTML = responseString[htmlid];
    			document.getElementById('hint-0').innerHTML ='';
    		}
    	}
	}
}

function grprecolindexshow(user,link,group,show) {
	//window.alert(link+','+group+','+show);
	url = $thisurl + "/group_recolindexshow.php";
	mycontent = "xmlhttp=true&user=" + user + "&link=" + link + "&group=" + group + "&show=" + show;
	//window.alert(mycontent);
	if (show > 0) {
		okhint = '成功设为精华人物';
		user = link;
	}
	else {
		okhint = '成功取消';
		user = 0;
	}
	document.getElementById('hint-'+user).innerHTML ='<span>正在处理，请稍候...</span>';
	htmlid = 1;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;   
    			//window.alert(responseString[htmlid]); 
    			if (responseString[htmlid].match('success')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:green">' + okhint + '</span>';
	    			renewrecollist(group);
	    			return;
    			}
    			if (responseString[htmlid].match('already')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:green">已经是精华人物</span>';
	    			return;
    			}
    			if (responseString[htmlid].match('full')) {
	    			document.getElementById('hint-'+user).innerHTML ='<span style="color:red">最多能设置8个物</span>';
	    			return;
    			}
    			document.getElementById('hint-'+user).innerHTML ='<span style="color:red">操作失败，请稍候再试或与站务青铜联系</span>';
    			return;
    		}
    	}
	}
}

function renewrecollist(group) {
	//window.alert(group);
	url = $thisurl + "/group_renewrecol.php";
	mycontent = "xmlhttp=true&group=" + group;
	//window.alert(mycontent);
	document.getElementById('hint-0').innerHTML ='<span style="color:green">操作成功，正在刷新，请稍候...</span>';
	htmlid = 2;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;
    			//window.alert(responseString[htmlid]);
    			document.getElementById('pusher').innerHTML = responseString[htmlid];
    			document.getElementById('hint-0').innerHTML ='';
    		}
    	}
	}
}

function groupapply(group, user) {
	if (user == 0) {
		//window.alert('请先登录');
		var urlstr = window.location.toString();
		window.location.href="login.php?return=" + urlstr;
		return;
	}
	//window.alert(group);
	url = $thisurl + "/group_apply.php";
	mycontent = "xmlhttp=true&group=" + group + "&user=" + user;
	//window.alert(mycontent);
	document.getElementById('hint-0').innerHTML ='<span style="color:green">正在处理，请稍候...</span>';
	htmlid = 2;
	mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
	if (mnmxmlhttp) {
		mnmxmlhttp[htmlid].open ("POST", url, true);
    	mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    	mnmxmlhttp[htmlid].send (mycontent);
    	mnmxmlhttp[htmlid].onreadystatechange = function () {
    		if (mnmxmlhttp[htmlid].readyState == 4) {
    			responseString[htmlid] = mnmxmlhttp[htmlid].responseText;
    			//window.alert(responseString[htmlid]);
    			if (responseString[htmlid].match('approved')) {
	    			document.getElementById('hint-0').innerHTML ='<span style="color:green">' + '已加入小组' + '</span>';
	    			return;
    			}
    			if (responseString[htmlid].match('applied')) {
	    			document.getElementById('hint-0').innerHTML ='<span style="color:green">' + '已申请，请等待小组管理员处理' + '</span>';
	    			return;
    			}
    			if (responseString[htmlid].match('fail')) {
	    			document.getElementById('hint-0').innerHTML ='<span style="color:red">' + '申请失败，请稍后再试或与站务青铜联系' + '</span>';
	    			return;
    			}
    			if (responseString[htmlid].match('deny')) {
	    			document.getElementById('hint-0').innerHTML ='<span style="color:red">' + '这是秘密小组，只有得到邀请后才能加入' + '</span>';
	    			return;
    			}
    		}
    	}
	}
}
function submit_comment_outside(status) {
	//submit_comment_outside_zuosa();
	//alert(document.getElementById('user_twitterout').value);
	if (document.getElementById('user_twitterout').value == 'true') {
		submit_comment_outside_twitter(status);
	}
	document.getElementById('outsidehint').innerHTML = '正在将评论保存到本站，请稍候...';
}
function submit_comment_outside_zuosa(status) {
	document.getElementById('zsctext').value = document.getElementById('comment').value;
	document.form1.status.value='[ '+location.href.replace(/#[A-Za-z-0-9]+/g, "")+' ] '+document.form1.status.value;
	xmlhttp = 'true';
	htmlid = 1;
	if (xmlhttp) {
		document.getElementById('outsidehint').innerHTML = '正在同步到做啥，请稍候...';
		url = "http://api.zuosa.com/statuses/update.xml";
		mycontent = "zsctext=" + document.getElementById('zsctext').value + '&enctype=multipart/form-data&target=zuosacomments';
		//alert(mycontent);
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true, "imniuna", "100100");
    		alert('sent');
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].setRequestHeader ('source','imniuna');
    		mnmxmlhttp[htmlid].setRequestHeader ('enctype',"multipart/form-data");
    		mnmxmlhttp[htmlid].setRequestHeader ('target',"zuosacomments");
    		mnmxmlhttp[htmlid].send (mycontent);
    		
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				//window.alert(mnmxmlhttp[htmlid].status);
    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;  
    				window.alert(responseString[htmlid]); 
    				document.getElementById('outsidehint').innerHTML = '已发送到做啥';
    			}
    		}
		}
	}
}

function submit_comment_outside_twitter(status) {
	
	//alert(status);
	twitter_uid = document.getElementById('user_twitteruid').value;
	twitter_pass = document.getElementById('user_twitterpass').value;
	if (status.length > 100) {
		status = status.substring(0,99) + '...';
	}
	status='[ '+location.href.replace(/#[A-Za-z-0-9]+/g, "")+' ] '+status + '\r\n' + 'From www.niuna.com ';
	xmlhttp = 'true';
	htmlid = 1;
	if (xmlhttp) {
		document.getElementById('outsidehint').innerHTML = '正在同步到Twitter，请稍候...';
		url = "http://twitter.com:80/statuses/update.xml";
		mycontent = "status=" + status;
		//alert(mycontent);
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
    		mnmxmlhttp[htmlid].open ("POST", url, true,twitter_uid,twitter_pass);
    		alert("opened xmlhttp");
    		mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
    		mnmxmlhttp[htmlid].send (mycontent);
    		alert('sent');
    		mnmxmlhttp[htmlid].onreadystatechange = function () {
    			alert(mnmxmlhttp[htmlid].readyState);
    			if (mnmxmlhttp[htmlid].readyState == 4) {
    				window.alert(mnmxmlhttp[htmlid].status);
    				if (mnmxmlhttp[htmlid].status == 200) {
	    				responseString[htmlid] = mnmxmlhttp[htmlid].responseText;  
	    				window.alert(responseString[htmlid]); 
	    				document.getElementById('outsidehint').innerHTML = '已同步到Twitter';
	    			}
    			}
    		}
		}
	}
}

